package com.ynwa.thread;

/**
 * thread join
 *
 * @author gzd
 * @date 2019-09-16 19:24
 */
public class ThreadJoin {


    public static void main(String[] args) {

        Thread firstThread = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("first started ...");
                for (int i = 0; i < 4; i++) {
                    try {
                        Thread.sleep(1000);
                        System.out.println("倒计时: " + i);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("first end ...");
            }
        });

        firstThread.start();

        Thread secondThread = new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    System.out.println("second start and join [first]... ");
                    firstThread.join();
                    System.out.println("join ended ... ");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        secondThread.start();

    }
}
